package work.xiaohong.mina.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author Kevin
 * @version 1.0
 * @date 2021/10/21 0021 11:01
 * @description 响应结果实体类
 */
@Data
@NoArgsConstructor
@Schema(description = "响应结果实体类")
public class Result<T> implements Serializable {
    @Schema(description = "响应状态标识")
    private boolean flag;
    @Schema(description = "响应码")
    private Integer code;
    @Schema(description = "响应提示信息")
    private String message;
    @Schema(description = "响应的数据")
    private T data;
    

    public Result(boolean flag, Integer code, String message, Object data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = (T) data;
    }

    public Result(boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }

    public static Result OK(String message){
        Result result = new Result();
        result.setFlag(true);
        result.setCode(StatusCode.OK);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public static Result OK(String message,Object data){
        Result result = new Result();
        result.setFlag(true);
        result.setCode(StatusCode.OK);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static Result ERROR(String message){
        Result result = new Result();
        result.setFlag(false);
        result.setCode(StatusCode.ERROR);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public static Result ERROR(String message,Object data){
        Result result = new Result();
        result.setFlag(false);
        result.setCode(StatusCode.ERROR);
        result.setMessage(message);
        result.setData(data);
        return result;
    }


}

